package com.goktech.project.hmw.dao.impl;

import com.goktech.project.hmw.dao.ISjDao;
import com.goktech.project.hmw.mapper.Sj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SjDaoImpl implements ISjDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	/**
	 * 通过peojectId获取数据集合
	 *
	 * @param project_id
	 * @return
	 */
	@Override
	public List<Sj> listSjByProjectId(String project_id) {
		String strSql="select * from sj where project_id = ? LIMIT 20";
		List<Sj> list =jdbcTemplate.query(strSql,new Object[]{project_id},new BeanPropertyRowMapper<>(Sj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}

	/**
	 * 通过idard获取数据集合
	 *
	 * @param idcard
	 * @return
	 */
	@Override
	public List<Sj> listSjByIdCard(String idcard) {
		String strSql="select * from sj where idcard = ? LIMIT 20";
		List<Sj> list =jdbcTemplate.query(strSql,new Object[]{idcard},new BeanPropertyRowMapper<>(Sj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}

	/**
	 * 通过姓名获取数据集合
	 *
	 * @param name
	 * @return
	 */
	@Override
	public List<Sj> listSjByName(String name) {
		String strSql="select * from sj where name = ? LIMIT 20";
		List<Sj> list =jdbcTemplate.query(strSql,new Object[]{name},new BeanPropertyRowMapper<>(Sj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}

	/**
	 * 通过年月获取数据
	 *
	 * @param grant_year
	 * @return
	 */
	@Override
	public List<Sj> ListSjByYear(String grant_year) {
		String strSql="select * from sj where grant_year = ? LIMIT 20";
		List<Sj> list =jdbcTemplate.query(strSql,new Object[]{grant_year},new BeanPropertyRowMapper<>(Sj.class));
		if(list!=null&&list.size()>0){
			return list;
		}else{
			return null;
		}
	}
}
